home *** CD-ROM | disk | FTP | other *** search
/ Group 42-Sells Out! - The Information Archive / Group 42 Sells Out (Group 42) (1996).iso / elect / servo_pr.asm < prev    next >
Assembly Source File  |  1995-11-17  |  3KB  |  98 lines

  1.          TITLE "Servo Controller"
  2.          LIST P = 16C55
  3. ;            DATE 01SEP94
  4. ;            AUTHOR RICK FARMER
  5. ;            FILE NAME servo.ASM
  6. ;              Clock = 4MHz -> 1 instruction takes 1us
  7. PIC55   equ     1FFH
  8. STATUS  equ     3h              ; F3 Reg is STATUS Reg.
  9. PortA   equ     5h
  10. PortB   equ     6h              ; I/O Port Assignments
  11. PortC   equ     7h
  12. PULSE   equ    0Bh              ; pulse time high
  13. DELAY   equ    0Ch              ; 1 ms count
  14. DOWN    equ    0Dh              ; # ms /4 of low time
  15. CAP     equ    0Eh              ; time to charge cap
  16. LOWPUL  equ    0FH              ; pulse time high for duty cycle
  17. Z       equ     2h
  18. C       equ     0h
  19. ;********************************************************************
  20.  
  21. START   MOVLW  B'000111'        ;Select RTCC, internal clock source
  22.                 ;  & prescale value = 256
  23.     OPTION                  ;Actually load OPTION reg.
  24.     movlw  00h              ;setup port A as output
  25.     tris   PortA 
  26.     movwf  PortA            ;clear port A
  27.     movlw  0FFh             ;setup ports B & C as input
  28.     tris   PortB
  29.     tris   PortC  
  30.  
  31. BEGIN   MOVLW  0FFh             ;load 1ms. counter
  32.     MOVWF  DELAY            ;get it into reg
  33.     BSF    PortA,0          ;start pulse output
  34.  
  35. HIMS    NOP                     ;force loop into 4 cycle duty (even #)
  36.     NOP
  37.     DECFSZ DELAY            ;loop for 1st 1ms. of duty cycle 
  38.      GOTO  HIMS
  39.  
  40. HIGH    NOP                     ;force loop into 4 cycle duty (even #)
  41.     NOP
  42.     NOP
  43.     DECFSZ PULSE            ;loop for high part of duty cycle 
  44.      GOTO  HIGH             ;while pulse > 0  
  45.     BCF    PortA,0          ;end pulse output
  46.     
  47. HIPUL   NOP                     ;force loop into 4 cycle duty (even #)
  48.     NOP                     ;duty cycle compensation
  49.     INCFSZ LOWPUL           ;loop for high part of duty cycle 
  50.      GOTO  HIPUL            ;while pulse > 0  
  51.  
  52.     MOVLW  03h              ;load # ms * 4 counter
  53.     MOVWF  DOWN             ;get it into reg
  54.     MOVLW  0FAh             ;load 1ms. counter
  55.     MOVWF  DELAY            ;get it into reg
  56.     
  57. LOW     NOP                     ;force loop into 4 cycle duty (even #)
  58.     NOP  
  59.       INLOOP  NOP           ;force loop into 4 cycle duty (even #)
  60.           NOP 
  61.            DECFSZ DELAY ;loop for low part of duty cycle 
  62.           GOTO INLOOP
  63.     DECFSZ DOWN             ;loop for low part of duty cycle 
  64.      GOTO  LOW
  65.  
  66.     movlw  0ffh             ;make rb1 an input
  67.     tris   PortB            ;to let the cap charge
  68.  
  69. CHARGE  INCFSZ   CAP,1          ;start timing loop
  70.      GOTO     NEXT          ;check for overflow
  71.     DECF     CAP,1          ;make it FFh
  72.     GOTO     DONE
  73. NEXT    NOP                     ;timing nop
  74.     NOP
  75.     BTFSS  PortB,1          ;check input pin RB1
  76.      GOTO   CHARGE          ;not charged yet
  77.  
  78. DONE    MOVF   CAP,0            ;but time in W
  79.     MOVWF  PULSE            ;save time in
  80.     MOVWF  LOWPUL
  81.  
  82. DUTY    NOP                     ;force this part to a constant 2ms
  83.     NOP
  84.     NOP
  85.     NOP
  86.     NOP
  87.     INCFSZ CAP,1            ;loop unit roll over for constant duty cycle
  88.      GOTO   DUTY            
  89.  
  90.     movlw  0fdh             ;make rb1 an output
  91.     tris   PortB            ;drive it low to discharge timing cap
  92.     bcf    PortB,1          ;for a constant time
  93.  
  94.     GOTO   BEGIN            ;restart loop
  95.     ORG    PIC55
  96.     GOTO   START
  97.     END
  98.